import 'package:flutter/material.dart';
import 'package:lucky_orbs/data/models/lottery_ticket.dart';

class TicketDisplay extends StatelessWidget {
  final LotteryTicket ticket;
  const TicketDisplay({super.key, required this.ticket});

  @override
  Widget build(BuildContext context) {
    return Card(
      color: Colors.black.withOpacity(0.3),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Wrap(
          alignment: WrapAlignment.center,
          spacing: 4.0, // 水平间距 / Horizontal spacing
          runSpacing: 12.0, // 垂直间距 / Vertical spacing
          children: [
            ...ticket.frontAreaNumbers
                .map((n) => _NumberChip(number: n, isFront: true)),
            // Container(
            //   width: 2,
            //   height: 20,
            //   color: Colors.white30,
            //   margin: const EdgeInsets.symmetric(horizontal: 8),
            // ),
            ...ticket.backAreaNumbers
                .map((n) => _NumberChip(number: n, isFront: false)),
          ],
        ),
      ),
    );
  }
}

class _NumberChip extends StatelessWidget {
  final int number;
  final bool isFront;

  const _NumberChip({required this.number, required this.isFront});

  @override
  Widget build(BuildContext context) {
    final color = isFront ? Colors.redAccent : Colors.blueAccent;
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 4),
      padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
      decoration: BoxDecoration(
        color: color.withOpacity(0.8),
        borderRadius: BorderRadius.circular(20),
        border: Border.all(color: color),
      ),
      child: Text(
        number.toString().padLeft(2, '0'),
        style:
            const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
      ),
    );
  }
}
